﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NVelocityInfo.cs" company="Collaboris Ltd.">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>
//   Defines a Class Store information about an NVelocitty Template
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Collaboris.Saf.Actions.Entities
{
    using System.Xml.Serialization;

    using Engine;

    using SharePoint.Wss.Attributes;
    using SharePoint.Wss.Entities;

    using Utils;

    [CollaborisClass(
      Title = "NVelocity Information class",
      ReleaseStatus = ReleaseStatus.Beta,
      DisableDocumentation = false,
      ContactAuthorEmail = "Support@Collaboris.co.uk",
      Summary = "This class supports the NVelocity action to pass parameters in."
    )]
    public class NVelocityInfo : EntityBase
    {
        private string outputFile;
        private string outputText;

        private string templateFile;
        
        private SerializableObjectDictionary<string> properties;

        private bool? includeSafProperties;

        private bool? replaceOutputFile;

        [CollaborisProperty(
              Summary = "Contains the rendered output from the NVelocity process.",
              Title = "Output Text",
              OutputProperty = true,
              Remarks = "This is useful if you wish to feed the text into a subsequent action."
        )]
        public string OutputText
        {
            get
            {
                return this.outputText;
            }
            set
            {
                this.outputText = value;
            }
        }

        [CollaborisProperty(
             Summary = "The full name and path to where the outputted file will be saved.",
             Title = "Output File",
             Example = @"${CurrentDirectory}\HelloWorld.vm",
             Remarks = "To replace the file, set 'ReplaceOutputFile' to 'True'",
             RenderAsExpression = false
             )]
        public string OutputFile
        {
            get
            {
                return this.outputFile;
            }
            set
            {
                this.outputFile = value;
            }
        }

        [CollaborisProperty(
             Summary = "The full name and path to NVelocity template file.",
             Title = "Template File",
             Example = @"${CurrentDirectory}\NvelocityTemplate.vm",
             RenderAsExpression = false
             )]
        public string TemplateFile
        {
            get
            {
                return templateFile;
            }
            set
            {
                templateFile = value;
            }
        }

        [CollaborisProperty(
            Summary = "Specifies the key " +
                     "and objects to use as properties within your NVelocity templates.",
            Title = "Properties",
            Example = @"<dictionary> " +
                        @"<entry key=""From"" value=""Mark.Jones@noreply.com"" />" +
                        @"<entry key=""To"" value=""Fred.Flinstone@noreply.com"" />" +
                        @"<entry key=""customerName"" value=""Fred"" />" +
                        @"<entry key=""Subject"" value=""NVelocity Generated Email"" />" +
                      @"</dictionary>",
            SerializedExample = @"<Dictionary type=""Collaboris.Utils.SerializableObjectDictionary`1[[System.String]]"">
					                <item type=""System.String"">
						                <key>
							                <string>Title</string>
						                </key>
						                <value>
							                <string>Introduction</string>
						                </value>
					                </item>
				                </Dictionary>",
            Remarks = "Properties contained used in this dictionary can then be referred to in the NVelodity template by prefixing with a dollar e.g. '$From' notation.",
            InputHint = InputHint.ObjectCollection,
            Required = true)]
        [XmlElement]
        public SerializableObjectDictionary<string> Properties
        {
            get
            {
                if (this.properties == null)
                {
                    properties = new SerializableObjectDictionary<string>();
                }

                return properties;
            }

            set
            {
                properties = value;
            }
        }

        [CollaborisProperty(
          Summary = "Defaults to 'True'. Specifies whether to include the SAF " +
                    "(contextual) properties passed in to the Macro by the adapter.",
          Title = "Include Saf Properties",
          Example="true",
          Remarks = @"This is particularly useful if you wish to consume placeholder values " + 
                     "within the NVelocity template.",
          InputHint = InputHint.Boolean)]
        [XmlElement(IsNullable = true)]
        public bool? IncludeSafProperties
        {
            get
            {
                return includeSafProperties;
            }
            set
            {
                includeSafProperties = value;
            }
        }

        [CollaborisProperty(
          Summary = "Defaults to 'True'. Specifies whether to overwrite the outputted " +
                    "file that NVelocity creates.",
          Title = "Replace Output File",
          Example = "true",
          InputHint = InputHint.Boolean)]
        [XmlElement(IsNullable = true)]
        public bool? ReplaceOutputFile
        {
            get
            {
                return this.replaceOutputFile;
            }
            set
            {
                this.replaceOutputFile = value;
            }
        }
    }
}
